package com.jerry.consumer.client;

import com.jerry.common.bean.Product;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class ProductFallbackFactory implements FallbackFactory<ProductClient> {

    @Override
    public ProductClient create(Throwable throwable) {
        return new ProductClient() {
            @Override
            public List<Product> list() {
                List<Product> productList = new ArrayList<Product>();
                Product product = new Product();
                product.setId(-1l);
                product.setName("数据库存中没有数据--@HystrixCommand");
                list().add(product);
                return  productList;
            }

            @Override
            public Product get(Long id) {
                System.out.println("进入回退方法，异常==="+throwable);

                Product product = new Product();
                product.setId(-1l);
                product.setName("数据库存中没有数据--@HystrixCommand");
                return  product;
            }

            @Override
            public boolean add(Product product) {
                System.out.println("新增方法发生异常");
                return false;
            }

            @Override
            public boolean update(Product product) {
                System.out.println("更新方法发生异常");
                return false;
            }

            @Override
            public void delete(Long id) {
                System.out.println("删除方法发生异常");
            }
        };
    }
}
